package main

import (
	"fmt"
)

func shortestToChar(s string, c byte) []int {
	chars := []byte(s)
	var ci []int
	for i, v := range chars {
		if v == c {
			ci = append(ci, i)
		}
	}
	var res []int
	left := -10001
	rIndex := 0
	right := ci[rIndex]
	for i := 0; i < len(s); i++ {
		fmt.Println(left, right, i)
		if i < right {
			res = append(res, min(i-left, right-i))
		} else {
			left = right
			if rIndex+1 < len(ci) {
				rIndex++
				right = ci[rIndex]
			} else {
				right = 20001
			}
			res = append(res, 0)
		}
	}
	return res
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	s := "loveleetcode"
	c := byte('e')
	res := shortestToChar(s, c)
	fmt.Println(res)
}
